package com.tee.web.action.privilege;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import com.tee.bean.privilege.PrivilegeGroup;
import com.tee.bean.privilege.SystemPrivilege;
import com.tee.bean.privilege.SystemPrivilegePK;
import com.tee.bean.privilege.User;

/** 
 * 权限检查标签类 
 */  
public class PermissionTag extends TagSupport {  
    private static final long serialVersionUID = -5285732412976711256L;  
  
    private String module;  
    private String privilege;  
  
    @Override  
    public int doStartTag() throws JspException {  
        boolean result = false;  
        User user = (User)pageContext.getSession().getAttribute("user");
        SystemPrivilege privilege = new SystemPrivilege(new SystemPrivilegePK(this.module, this.privilege));  
        for (PrivilegeGroup group : user.getGroups()) {  
            if (group.getPrivileges().contains(privilege)) {  
                result = true;  
                break;  
            }  
        }  
        return result ? EVAL_BODY_INCLUDE : SKIP_BODY;  
    }  
  
    public String getModule() {  
        return module;  
    }  
  
    public void setModule(String module) {  
        this.module = module;  
    }  
  
    public String getPrivilege() {  
        return privilege;  
    }  
  
    public void setPrivilege(String privilege) {  
        this.privilege = privilege;  
    }  
}  